package com.rwx.myjetpack.musiclist

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.rwx.myjetpack.R
import com.rwx.myjetpack.base.BaseActivity
import com.rwx.myjetpack.databinding.ActivityMusicListBinding
import com.rwx.myjetpack.lifecycle.ILifecycleOwner
import com.rwx.myjetpack.lifecycle.LifecycleProvider
import com.rwx.myjetpack.player.PlayerPresenter

class MusicListActivity : BaseActivity() {

    val binding by lazy { ActivityMusicListBinding.inflate(layoutInflater) }

    val musicPresenter by lazy { MusicListPresenter(this) }
    val playerPresenter by lazy {
        PlayerPresenter.instance
    }
    init {

//        addLifeListener(musicPresenter)
//        addLifeListener(playerPresenter)
//        lifeProvider.addLifeListener(musicPresenter)
//        lifeProvider.addLifeListener(playerPresenter)

    }



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)


        initListener()

        initDataListener()



    }


    private fun initDataListener() {
        println("加载状态Thread~~~~~${Thread.currentThread().name}")
        musicPresenter.musicList.addListener(this) {
            println("加载状态~~~~~${it?.size}")
            println("加载状态~~~~~${Thread.currentThread().name}")



        }

        musicPresenter.loadState.addListener(this) {
            println("加载状态~~~~~$it")
        }

    }

    private fun initListener() {

        binding.btmMusicList.setOnClickListener {
            musicPresenter.getMusic()
        }


    }




}
